/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package backupBeans;

import backupBusiness.BackupBusiness;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Chucho
 */
@ManagedBean
@RequestScoped
public class BackupBean {
    private String user;
    private String password;
    private String port;
    private String path;
    private List<String> dumps;

    public BackupBean() {
        reloadtables();
    }
    public void reloadtables() {
        FacesContext fc = FacesContext.getCurrentInstance();
        try {
            this.dumps = new BackupBusiness().getDumps();
        } catch (SQLException ex) {
        }
    }

    public List<String> getDumps() {
        return dumps;
    }

    public void setDumps(List<String> dumps) {
        this.dumps = dumps;
    }
    
    public String getUser() {
        return user;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public void setUser(String user) {
        this.user = user;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPort() {
        return port;
    }

    public void setPort(String port) {
        this.port = port;
    }
    public void makeBackup() {
        
        String message = new BackupBusiness().doBackUp(user, password, port, path);
        FacesContext fc = FacesContext.getCurrentInstance();
        reloadtables();
        user = "";
        password = "";
        port = "";
        path = "";
        fc.addMessage(null, new FacesMessage("Mensaje", message));
    }
}
